<?php

/**
 * Menashop
 *
 * LICENSE
 *
 * This source file is subject to the license that is bundled
 * with this project in the file LICENSE.txt
 *
 * @category   Zend
 * @package    Admin_Model
 * @subpackage FormPriceRule
 * @copyright  Copyright (c) 2011 Menashop UA Inc. (http://www.menashop.com.ua)
 * @license    LICENSE.txt
 * @version    1.0.0
 * @since      File available since Release 1.0.0
 */

/**
 * The form for priceRule
 * 
 * @category   Zend
 * @package    Admin_Model
 * @subpackage FromPriceRule
 * @copyright  Copyright (c) 2011 Menashop UA Inc. (http://www.menashop.com.ua)
 * @license    LICENSE.txt
 */
class Admin_Model_FormPriceRule extends Zend_Form
{
    /**
     * Language ID
     * @var integer
     */
    protected $_languageId = null;
    
    public function __construct($options = null)
    {
        $this->_languageId = $options['languageId'];
        parent::__construct($options);
    }

    public function init()
    {
        $this->setMethod('post');

        $id = new Zend_Form_Element_Hidden('id');
        $id->removeDecorator('label');
        $id->removeDecorator('htmlTag');
        $this->addElement($id);

        $category = new Zend_Form_Element_Select('category');
        $categoryModel = new Admin_Model_Category();
        $categories = $categoryModel->fetchAllForDropdown($this->_languageId);
        $category->addMultiOption('', '');
        foreach ($categories as $key => $value) {
            $category->addMultiOption($key, $value);
        }
        $category->removeDecorator('label');
        $category->removeDecorator('htmlTag');
        $category->removeDecorator('Errors');
        $this->addElement($category);

        $manufacturer = new Zend_Form_Element_Select('manufacturer');
        $manufacturerModel = new Admin_Model_Manufacturer();
        $manufacturers = $manufacturerModel->fetchAllForDropdown();
        $manufacturer->addMultiOption('', '');
        foreach ($manufacturers as $key => $value) {
            $manufacturer->addMultiOption($key, $value);
        }
        $manufacturer->removeDecorator('label');
        $manufacturer->removeDecorator('htmlTag');
        $manufacturer->removeDecorator('Errors');
        $this->addElement($manufacturer);

        $product = new Zend_Form_Element_Text('product');
        $product->addValidator('Int');
        $product->addErrorMessage('Please provide correct product');
        $product->removeDecorator('label');
        $product->removeDecorator('htmlTag');
        $product->removeDecorator('Errors');
        $this->addElement($product);

        $markup = new Zend_Form_Element_Text('markup');
        $markup->setRequired(true);
        $markup->addValidator(new Zend_Validate_Float(array('locale' => 'en_us')));
        $markup->addErrorMessage('Please provide correct markup');
        $markup->removeDecorator('label');
        $markup->removeDecorator('htmlTag');
        $markup->removeDecorator('Errors');
        $this->addElement($markup);

        $priority = new Zend_Form_Element_Text('priority');
        $priority->setRequired(true);
        $priority->addValidator('Int');
        $priority->addErrorMessage('Please provide correct priority');
        $priority->removeDecorator('label');
        $priority->removeDecorator('htmlTag');
        $priority->removeDecorator('Errors');
        $this->addElement($priority);

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Save');
        $submit->removeDecorator('DtDdWrapper');
        $this->addElement($submit);

        $this->setDecorators(array(array('ViewScript', array('viewScript' => '_form_price_rule.phtml'))));
    }

}

